<?php
/**
 * Created by PhpStorm.
 * User: li
 * Date: 15-10-18
 * Time: 下午11:01
 */
class Account extends MY_Action_Controller{

    function __construct(){
        parent::__construct();
    }

    /**
     * 获取用户信息  GET
     *
     */
    function get(){
        $user_id = intval($this->input->get('user_id'));
        $this->_check_user($user_id);
        $this->load->model('users/User_model');
        $user = $this->User_model->get_user_by_id($user_id);
        if(!$user){
            $this->set_response(10500);
        }
        $this->set_response(0);
    }

    /**
     * 更新用户信息  POST
     *
     */
    function do_update(){
        $user_id = $this->input->post('user_id');
        $this->_check_user($user_id);
        $data = array(
            'id'        =>  $user_id,
            'username'  =>  $this->input->post('username'),
            'nickname'  =>  $this->input->post('nickname'),
            'gender'    =>  $this->input->post('gender'),
            'tags'      =>  $this->input->post('tags'),
            'avatar'    =>  $this->input->post('avatar'),
            'introduce' =>  $this->input->post('introduce'),
            'birthday'  =>  $this->input->post('year').'-'.$this->input->post('month').'-'.$this->input->post('day')
        );
        $this->load->model('users/User_model');
        if($this->User_model->update($data)){
            $this->set_response(0);
        }
        $this->set_response(10500);
    }

    /**
     * 上传头像、更新头像
     */
    function do_upload_avatar(){
        //TODO：
    }

    private function _check_user($user_id){
        if(!$user_id){
            $this->set_response(10403);
        }
        if($user_id!=$this->_login_user['user_id']){
            $this->set_response(10403);
        }
    }

}